package com.ruge.system.controller;

import com.ruge.common.util.RestResponse;
import com.ruge.system.pojo.entity.SysMenu;
import com.ruge.system.pojo.request.MenuRequest;
import com.ruge.system.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2020-03-06  12:07
 * 描述 ：
 * @author Administrator
 */
@RestController
@RequestMapping("/menu")
@Api(value = "菜单controller", tags = {"菜单操作接口"})
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;

    @GetMapping
    @ApiOperation(value = "获取菜单列表信息", notes = "获取菜单列表信息")
    public RestResponse list(MenuRequest  request) {
        return RestResponse.success().setData(sysMenuService.findAll(request));
    }

    @GetMapping("noPage")
    @ApiOperation(value = "获取菜单列表信息", notes = "获取菜单列表信息")
    public RestResponse noPage(MenuRequest  request) {
        return RestResponse.success().setData(sysMenuService.findAllNoPage(request));
    }

    @PostMapping
    @ApiOperation(value = "保存菜单详细信息")
    public RestResponse save(@RequestBody SysMenu sysMenu) {
        return RestResponse.success().setData(sysMenuService.save(sysMenu));
    }

    @ApiOperation(value = "更新菜单详细信息")
    @PutMapping
    public RestResponse update(@RequestBody SysMenu sysMenu) {
        return RestResponse.success().setData(sysMenuService.save(sysMenu));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除菜单", notes = "根据url的id来指定删除对象")
    public RestResponse delete(@PathVariable Long id) {
        sysMenuService.deleteById(id);
        return RestResponse.success();
    }

    @ApiOperation(value = "批量操作", notes = "根据url的id来指定批量操作对象")
    @PostMapping("/batch")
    public RestResponse batch(@RequestBody Map<String, List<SysMenu>> map) {
        return RestResponse.success().setData(sysMenuService.batch(map));
    }
}
